Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove FixedShapedIterator #131

Merged
merged 5 commits into from
Dec 11, 2024
Merged

Remove FixedShapedIterator #131

merged 5 commits into from
Dec 11, 2024

Conversation

THinnerichs
Copy link
Member

Addresses #130 . For iterating uniform trees, see UniformIterator.

@THinnerichs THinnerichs requested a review from ReubenJ November 23, 2024 12:06
@THinnerichs THinnerichs self-assigned this Nov 23, 2024
@ReubenJ
Copy link
Member

ReubenJ commented Nov 25, 2024

Either #107 should be merged before this, or this should be merged into the branch of #107 (bottom-up-iterator), not master.

@THinnerichs THinnerichs changed the base branch from master to dev December 5, 2024 10:37
Copy link
Member

@ReubenJ ReubenJ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly stylistic changes. If they're too nit-picky, I'm happy to merge as-is.

Specialization of `BottomUpState`'s `BottomUpData` type. Contains the following:
* `nested_rulenode_iterator::NestedRulenodeIterator`: Iterator generating `RuleNodes` using a grammar rule to combine existing `RuleNodes` from the `bank`.
* `new_programs::Vector{RuleNode}`: Programs generated at the current depth level. Will be appended to the `bank` when starting a new depth level.
* `rules::Queue{Int}`: Grammar rules left to be used at the current depth level.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we maybe call this unused_rules?


Returns the non-terminal rules in the order in which they appear in the grammar.
"""
function order(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

order is too vague. I suggest we make the function name more descriptive (ordered_nonterminals?). Also, I believe this should be possible with a one-liner Queue(grammar.rules[grammar.isterminal]) or something like this.

Comment on lines 104 to 107
Returns the next program in `BUDepthIterator`'s iteration. Performs the following steps:
1. Check whether `data.nested_rulenode_iterator` contains any program.
2. Otherwise, pick the next rule from `data.rules` and generate all combinations of `RuleNodes` from the bank that could be combined using this rule.
3. If `data.rules` is empty, call `_increase_depth!` and go to step 2.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer the docstring to not contain the steps of the function like this with all of the implementation details—that's what the source is for. Maybe we move the comments into inline comments and keep this part more general. I just worry the two will get out of sync of there are changes.

Comment on lines 176 to 181
Performs the following steps required when the depth is increased:
* Increase `data.depth`.
* Create a new `data.rules` queue consisting of the indices of non-terminal rules in the grammar.
* Copy all programs from `data.new_programs` to the `bank`.
* Go to Step 2.
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, this feels a bit verbose for a docstring.

Comment on lines 56 to 63
"""
init_bank(iter::BUDepthIterator)::BUDepthBank

Returns an initialized object of type `BUDepthBank`. For each symbol in the grammar (i.e. key in the dictionary), an empty `Vector{RuleNode}` (i.e. value in the dictionary) is allocated.
"""
function init_bank(
iter::BUDepthIterator
)::BUDepthBank
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a motivation for not making this a constructor of BUDepthBank?

Comment on lines 74 to 85
"""
init_data(iter::BUDepthIterator)::BUDepthData

Returns an initialized object of type `BUDepthData`. The initialization consists of the following:
* `nested_rulenode_iterator` is set to an empty `NestedRulenodeIterator`.
* `rules` contains the indeces of terminal rules in the grammar.
* `new_programs` is an empty `Vector{RuleNode}`.
* `depth` is set to 1.
"""
function init_data(
iter::BUDepthIterator
)::BUDepthData
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here—I think this can be a constructor.

Comment on lines 16 to 19
Observational equivalence (i.e. removing programs which yield the same outputs on all examples) is an optional optimization which could be used by `BottomUpIterator`s.
To enable it, add the following fields to the `BottomUpIterator` implementation:
- `problem::Union{Nothing, Problem{Vector{IOExample}}}.
- `obs_equivalence::Bool` (and set this to `true` when creating the `BottomUpIterator`).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would ideally be a HasObsEquivalence trait instead, but if this approach works, I'm fine leaving it as is. It just makes the code for _has_obs_equivalence not-so-pretty.


Returns an initialized object of type `BUDepthBank`. For each symbol in the grammar (i.e. key in the dictionary), an empty `Vector{RuleNode}` (i.e. value in the dictionary) is allocated.
"""
function init_bank(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function init_bank(
function BUUniformBank(

possibly?

* `new_programs` is an empty `Vector{RuleNode}`.
* `depth` is set to 1.
"""
function init_data(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function init_data(
function BUUniformData(

Copy link

codecov bot commented Dec 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 71.26%. Comparing base (c4c6deb) to head (b9ad9ab).
Report is 6 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #131      +/-   ##
==========================================
+ Coverage   67.53%   71.26%   +3.72%     
==========================================
  Files          21       20       -1     
  Lines         727      689      -38     
==========================================
  Hits          491      491              
+ Misses        236      198      -38     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ReubenJ
Copy link
Member

ReubenJ commented Dec 10, 2024

Fixed failing CI due to exporting non-existent symbols. Nightly is still failing because changes from #128 are not on this branch yet. I would be in favor of rebasing this branch on top of master and merging directly into master with a patch version bump.

THinnerichs and others added 3 commits December 11, 2024 15:13
Add `Aqua.jl` to test for this in the future as well as other Aqua
tests. Ignoring the type piracies on `RuleNode`s and
`AbstractGrammar`. Ideally, this functionality would be moved to
`HerbCore`, but that can wait.
@ReubenJ ReubenJ force-pushed the remove_fixedshape_iterator branch from 2c16416 to 00fdacf Compare December 11, 2024 12:17
@ReubenJ ReubenJ changed the base branch from dev to master December 11, 2024 13:30
@ReubenJ ReubenJ self-requested a review December 11, 2024 13:32
@THinnerichs THinnerichs merged commit 9ff0f71 into master Dec 11, 2024
5 checks passed
@THinnerichs THinnerichs deleted the remove_fixedshape_iterator branch December 11, 2024 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants